<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3_2_4-属性侦听器</title>
</head>

<body>


  <!--载入vue.js-->
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application">
    <input v-model="searchText" />
  </div>

  <script>
    //定义组件
    const App = {
      //组件的data方法
      data() {
        //返回对象
        return {
          searchText: "",
        };
      },
      //计算属性
      computed: {},
      //属性侦听
      watch: {
        searchText(oldValue, newValue) {
          if (newValue.length > 10) {
            alert("文本太长了");
          }
        },
      },

      //组件的方法
      methods: {},
    };

    Vue.createApp(App).mount("#Application");
  </script>
</body>

</html>